<?php

class Notices extends AppModel {

    var $alias = 'Notices';
    var $name = 'Notices';
    var $useTable = 'notices';

    function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
        $parameters = compact('conditions');
        $this->recursive = $recursive;
        $count = $this->find('count', array_merge($parameters, $extra));
        if (isset($extra['group'])) {
            $count = $this->getAffectedRows();
        }
        return $count;
    }
    function notice($limit = 1){
        $data = $this->find('all', array(
                    'conditions' => array('Notices.published' => '1'),
                    'fields' => array('Notices.id', 'Notices.alias', 'Notices.short_description', 'Notices.title'),
                    'order' => 'Notices.id DESC',
                    'limit' => $limit,
                    'offset'    =>  0
        ));
        $html   =   '';
        foreach($data AS $row){
            $html .=    '<div class="comment-row">';
            $html .=    "<h3>{$row['Notices']['title']}</h3>";
            $html .=    '<p><img src="/img/icon-lastestComment.png" alt="xem thông báo này" width="17px" height="17px" />
                <img src="/img/thongbao_icon.gif" alt="icon thông báo" width="70px" height="70px" style="height: 50px; width: 50px;"/>
                <a class="notice-shortcontent" href="/thong-bao/' . $row['Notices']['id'] . '-' . $row['Notices']['alias'] . '.html' . '" title="xem thông báo này">' . $row['Notices']['short_description'] . '</a> </p>';
            $html .=    '</div>';
        }
        $resourse = fopen(CAKE_CORE_INCLUDE_PATH . DS . 'app' . DS . 'views' . DS . 'elements' . DS . 'notice.ctp', 'w');
        fwrite($resourse, $html);
    }
}

?>
